package com.example.iso9797demo;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    /**
     * ISO9797 算法 3 MAC 计算器主界面
     *
     * 功能：
     * 1. 支持双长度(16字节)和三长度(24字节)密钥
     * 2. 支持 ISO7816-4 填充
     * 3. 实时计算 MAC 值并显示结果
     */

    int[] testDataSize = {256, 1024, 4096};
    // Tab按钮
    private Button btnHexTab;
    private Button btnByteTab;
    
    // 十六进制输入控件
    private EditText etInputDataHex;
    private EditText etKeyHex;
    private EditText etIvHex;
    
    // 字节数组输入控件
    private EditText etInputDataByte;
    private EditText etKeyByte;
    private EditText etIvByte;
    
    // 内容布局
    private View layoutHexContent;
    private View layoutByteContent;
    
    private RadioGroup rgPaddingMode;
    private Button btnCalculateMac;
    private TextView tvResult;
    private ScrollView scrollView;
    
    private ISO9797MacHelper macHelper;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        // 初始化视图
        initViews();
        
        // 初始化 MAC 计算助手
        macHelper = new ISO9797MacHelper();
        
        // 设置默认测试数据
        setDefaultData();

        // 遍历测试数据大小
        for (int dataSize : testDataSize) {
            runHexExamplePerformanceTest(dataSize);
        }

        // 设置Tab切换监听器
        setupTabListeners();
        
        // 设置计算按钮点击事件
        btnCalculateMac.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                calculateMac();
            }
        });
    }
    
    /**
     * 初始化视图组件
     */
    private void initViews() {
        // Tab按钮
        btnHexTab = findViewById(R.id.btn_hex_tab);
        btnByteTab = findViewById(R.id.btn_byte_tab);
        
        // 十六进制输入控件
        etInputDataHex = findViewById(R.id.et_input_data_hex);
        etKeyHex = findViewById(R.id.et_key_hex);
        etIvHex = findViewById(R.id.et_iv_hex);
        
        // 字节数组输入控件
        etInputDataByte = findViewById(R.id.et_input_data_byte);
        etKeyByte = findViewById(R.id.et_key_byte);
        etIvByte = findViewById(R.id.et_iv_byte);
        
        // 内容布局
        layoutHexContent = findViewById(R.id.layout_hex_content);
        layoutByteContent = findViewById(R.id.layout_byte_content);
        
        rgPaddingMode = findViewById(R.id.rg_padding_mode);
        btnCalculateMac = findViewById(R.id.btn_calculate_mac);
        tvResult = findViewById(R.id.tv_result);
        scrollView = findViewById(R.id.scroll_view);
    }
    
    /**
     * 设置默认测试数据（使用测试用例中的数据）
     */
    private void setDefaultData() {
        // 十六进制示例数据
        etInputDataHex.setText("84E400800F4F05474D504B49");
        etKeyHex.setText("319CD05D11BB06729BE23DA19B80E6A3");
        etIvHex.setText("A097994108D06F1B");
        
        // 字节数组示例数据
        etInputDataByte.setText("[-124,-28,0,-128,15,79,5,71,77,80,75,73]");
        etKeyByte.setText("[49,-100,-48,93,17,-69,6,114,-101,-30,61,-95,-101,128,-26,-93]");
        etIvByte.setText("[-96,-105,-103,65,8,-48,111,27]");
    }
    
    /**
     * 设置Tab切换监听器
     */
    private void setupTabListeners() {
        btnHexTab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchToHexTab();
            }
        });
        
        btnByteTab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchToByteTab();
            }
        });
    }
    
    /**
     * 切换到十六进制Tab
     */
    private void switchToHexTab() {
        // 更新按钮样式
        btnHexTab.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
        btnHexTab.setTextColor(getResources().getColor(android.R.color.white));
        btnByteTab.setBackgroundColor(getResources().getColor(R.color.button_gray));
        btnByteTab.setTextColor(getResources().getColor(R.color.text_gray));
        
        // 显示十六进制内容，隐藏字节数组内容
        layoutHexContent.setVisibility(View.VISIBLE);
        layoutByteContent.setVisibility(View.GONE);
    }
    
    /**
     * 切换到字节数组Tab
     */
    private void switchToByteTab() {
        // 更新按钮样式
        btnByteTab.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
        btnByteTab.setTextColor(getResources().getColor(android.R.color.white));
        btnHexTab.setBackgroundColor(getResources().getColor(R.color.button_gray));
        btnHexTab.setTextColor(getResources().getColor(R.color.text_gray));
        
        // 显示字节数组内容，隐藏十六进制内容
        layoutByteContent.setVisibility(View.VISIBLE);
        layoutHexContent.setVisibility(View.GONE);
    }
    
    /**
     * 计算 MAC 值
     */
    private void calculateMac() {
        try {
            // 判断当前是哪个Tab
            boolean isHexTab = (layoutHexContent.getVisibility() == View.VISIBLE);
            
            // 获取输入数据
            String inputText, keyText, ivText;
            boolean isInputDataHex, isKeyHex, isIvHex;
            
            if (isHexTab) {
                // 十六进制Tab
                inputText = etInputDataHex.getText().toString().trim();
                keyText = etKeyHex.getText().toString().trim();
                ivText = etIvHex.getText().toString().trim();
                isInputDataHex = true;
                isKeyHex = true;
                isIvHex = true;
            } else {
                // 字节数组Tab
                inputText = etInputDataByte.getText().toString().trim();
                keyText = etKeyByte.getText().toString().trim();
                ivText = etIvByte.getText().toString().trim();
                isInputDataHex = false;
                isKeyHex = false;
                isIvHex = false;
            }
            
            // 验证输入
            if (inputText.isEmpty()) {
                showError("请输入数据");
                return;
            }
            if (keyText.isEmpty()) {
                showError("请输入密钥");
                return;
            }
            
            // 解析输入数据
            byte[] inputBytes;
            if (isHexTab) {
                // 检查十六进制字符串长度是否为偶数
                String cleanInput = inputText.replaceAll("\\s+", "");
                if (cleanInput.length() % 2 != 0) {
                    showError("输入数据错误！\n\n十六进制字符串长度必须是偶数");
                    return;
                }
                inputBytes = macHelper.hexStringToBytes(inputText);
            } else {
                inputBytes = parseByteArray(inputText);
            }
            
            // 解析密钥
            String keyHex;
            if (isHexTab) {
                // 检查密钥十六进制字符串长度是否为偶数
                String cleanKey = keyText.replaceAll("\\s+", "");
                if (cleanKey.length() % 2 != 0) {
                    showError("密钥错误！\n\n十六进制字符串长度必须是偶数");
                    return;
                }
                keyHex = keyText.replaceAll("\\s+", "");
            } else {
                // 检查字节数组格式是否有效
                try {
                    byte[] keyBytes = parseByteArray(keyText);
                    keyHex = bytesToHexString(keyBytes);
                } catch (Exception e) {
                    showError("密钥错误！\n\n" + e.getMessage());
                    return;
                }
            }
            
            // 验证密钥长度
            if (keyHex.length() != 32 && keyHex.length() != 48) {
                showError(
                    "密钥长度错误！\n\n" +
                    "双长度密钥: 32 个十六进制字符（16 字节）\n" +
                    "三长度密钥: 48 个十六进制字符（24 字节）\n\n" +
                    "当前长度：" + (keyHex.length() / 2) + " 字节"
                );
                return;
            }
            
            // 解析 IV
            String ivHex = null;
            if (!ivText.isEmpty()) {
                if (isHexTab) {
                    // 检查IV十六进制字符串长度是否为偶数
                    String cleanIv = ivText.replaceAll("\\s+", "");
                    if (cleanIv.length() % 2 != 0) {
                        showError("IV错误！\n\n十六进制字符串长度必须是偶数");
                        return;
                    }
                    ivHex = ivText.replaceAll("\\s+", "");
                } else {
                    // 检查IV字节数组格式是否有效
                    try {
                        byte[] ivBytes = parseByteArray(ivText);
                        ivHex = bytesToHexString(ivBytes);
                    } catch (Exception e) {
                        showError("IV错误！\n\n" + e.getMessage());
                        return;
                    }
                }
                
                // 验证 IV 长度
                if (ivHex.length() != 16) {
                    showError(
                        "IV 长度错误！\n\n" +
                        "IV 必须是 16 个十六进制字符（8 字节）\n\n" +
                        "当前长度：" + (ivHex.length() / 2) + " 字节"
                    );
                    return;
                }
            }
            
            // 计算 MAC
            String macResult = macHelper.calculateMACFromBytesWithPadding(inputBytes, keyHex, ivHex, "ISO7816d4Padding");
            
            // 显示结果
            displayResult(inputText, keyText, ivText, 
                isInputDataHex, isKeyHex, isIvHex,
                    "ISO7816d4Padding", macResult);
            
        } catch (Exception e) {
            showError("计算失败：" + e.getMessage());
            e.printStackTrace();
        }
    }
    
    /**
     * 计算MAC并记录详细耗时
     */
    private void calculateMACWithDetailedTiming(byte[] dataBytes, String keyHex, String ivHex) throws Exception {
        // 初始化 MAC 计算助手
        // 创建 MAC 实例
        long timeS1 = System.nanoTime();
        org.bouncycastle.crypto.macs.ISO9797Alg3Mac machelper = new org.bouncycastle.crypto.macs.ISO9797Alg3Mac(
            new org.bouncycastle.crypto.engines.DESEngine(), 
            macHelper.createPadding("ISO7816d4Padding")
        );
        long timeE1 = System.nanoTime();
        double duration1 = (timeE1 - timeS1) / 1_000_000.0; // 转换为毫秒
        Log.i("ISO9797Alg3Mac", "testlog:: ISO9797Alg3Mac getAlgorithmName 耗时为 : " + String.format("%.3f", duration1) + "ms");
        // 准备密钥和IV
        byte[] keyBytes = macHelper.hexStringToBytes(keyHex);
        byte[] ivBytes = null;
        if (ivHex != null && !ivHex.isEmpty()) {
            ivBytes = macHelper.hexStringToBytes(ivHex);
        }
        // 测试 init
        long timeS2 = System.nanoTime();
        if (ivBytes != null) {
            machelper.init(new org.bouncycastle.crypto.params.ParametersWithIV(
                new org.bouncycastle.crypto.params.KeyParameter(keyBytes), ivBytes));
        } else {
            machelper.init(new org.bouncycastle.crypto.params.KeyParameter(keyBytes));
        }
        long timeE2 = System.nanoTime();
        double duration2 = (timeE2 - timeS2) / 1_000_000.0;
        Log.i("ISO9797Alg3Mac", "testlog:: ISO9797Alg3Mac init 耗时为 : " + String.format("%.3f", duration2) + "ms");
        // 测试 update
        long timeS3 = System.nanoTime();
        machelper.update(dataBytes, 0, dataBytes.length);
        long timeE3 = System.nanoTime();
        double duration3 = (timeE3 - timeS3) / 1_000_000.0;
        Log.i("ISO9797Alg3Mac", "testlog:: ISO9797Alg3Mac update 耗时为 : " + String.format("%.3f", duration3) + "ms");
        // 测试 getMacSize
        long timeS4 = System.nanoTime();
        int macSize = machelper.getMacSize();
        long timeE4 = System.nanoTime();
        double duration4 = (timeE4 - timeS4) / 1_000_000.0;
        Log.i("ISO9797Alg3Mac", "testlog:: ISO9797Alg3Mac getMacSize 耗时为 : " + String.format("%.3f", duration4) + "ms");
        // 准备输出数组
        byte[] output = new byte[8];
        long timeS5 = System.nanoTime();
        machelper.doFinal(output, 0);
        long timeE5 = System.nanoTime();
        double duration5 = (timeE5 - timeS5) / 1_000_000.0;
        Log.i("ISO9797Alg3Mac", "testlog:: ISO9797Alg3Mac doFinal 耗时为 : " + String.format("%.3f", duration5) + "ms");
        // 测试 updateByte
        long timeS6 = System.nanoTime();
        // android 源库 就是 重写的 update
        machelper.update((byte) 100);
        long timeE6 = System.nanoTime();
        double duration6 = (timeE6 - timeS6) / 1_000_000.0;
        Log.i("ISO9797Alg3Mac", "testlog:: ISO9797Alg3Mac updateByte 耗时为 : " + String.format("%.3f", duration6) + "ms");
        // 测试 reset
        long timeS7 = System.nanoTime();
        machelper.reset();
        long timeE7 = System.nanoTime();
        double duration7 = (timeE7 - timeS7) / 1_000_000.0;
        Log.i("ISO9797Alg3Mac", "testlog:: ISO9797Alg3Mac reset 耗时为 : " + String.format("%.3f", duration7) + "ms");
        // 输出结果
        String outputStr = java.util.Arrays.toString(output);
        // 测试填充相关方法
        org.bouncycastle.crypto.paddings.BlockCipherPadding padding = macHelper.createPadding("ISO7816d4Padding");
        
        // 测试 padding.init
        long timeS = System.nanoTime();
        if ("ISO10126d2Padding".equals("ISO10126d2Padding")) {
            padding.init(new java.security.SecureRandom());
        } else {
            padding.init(null);
        }
        long timeE = System.nanoTime();
        double duration = (timeE - timeS) / 1_000_000.0;
        Log.i("ISO9797Alg3Mac", "testlog:: ISO9797Alg3Mac padding.init 耗时为 : " + String.format("%.3f", duration) + "ms");
        // 测试 padding.getPaddingName
        long timeSt = System.nanoTime();
        String paddingName = padding.getPaddingName();
        long timeEn = System.nanoTime();
        double durationPadName = (timeEn - timeSt) / 1_000_000.0;
        Log.i("ISO9797Alg3Mac", "testlog:: ISO9797Alg3Mac padding.getPaddingName 耗时为 : " + String.format("%.3f", durationPadName) + "ms");
        // 测试 padding.addPadding
        long timeS0 = System.nanoTime();
        byte[] paddedData = new byte[keyBytes.length + 8]; // 创建足够大的数组
        System.arraycopy(keyBytes, 0, paddedData, 0, keyBytes.length);
        int paddingCount = padding.addPadding(paddedData, keyBytes.length);
        long timeE0 = System.nanoTime();
        double durationAddPad = (timeE0 - timeS0) / 1_000_000.0;
        Log.i("ISO9797Alg3Mac", "testlog:: ISO9797Alg3Mac padding.addPadding 耗时为 : " + String.format("%.3f", durationAddPad) + "ms");

    }
    
    /**
     * 根据指定的填充模式计算MAC
     */
    private String calculateMACWithPadding(byte[] dataBytes, String keyHex, String ivHex, String paddingMode) throws Exception {
        return macHelper.calculateMACFromBytesWithPadding(dataBytes, keyHex, ivHex, paddingMode);
    }
    
    /**
     * 显示计算结果
     */
    private void displayResult(String inputText, String keyText, String ivText,
                               boolean isInputDataHex, boolean isKeyHex, boolean isIvHex,
                               String paddingMode, String macValue) {
        StringBuilder sb = new StringBuilder();
        
        sb.append("========== 计算成功 ==========\n\n");
        
        sb.append("【输入信息】\n");
        sb.append("输入模式: ").append(isInputDataHex ? "十六进制" : "字节数组").append("\n");
        sb.append("数据: ").append(inputText.length() > 50 ? inputText.substring(0, 50) + "..." : inputText).append("\n");
        
        // 尝试解析数据长度
        int dataLength = 0;
        try {
            if (isInputDataHex) {
                dataLength = macHelper.hexStringToBytes(inputText).length;
            } else {
                dataLength = parseByteArray(inputText).length;
            }
            sb.append("数据长度: ").append(dataLength).append(" 字节\n");
        } catch (Exception e) {
            sb.append("数据长度: 无法解析\n");
        }
        sb.append("\n");
        
        sb.append("【密钥信息】\n");
        sb.append("输入模式: ").append(isKeyHex ? "十六进制" : "字节数组").append("\n");
        
        // 获取密钥的十六进制表示
        String keyHex;
        try {
            if (isKeyHex) {
                keyHex = keyText.replaceAll("\\s+", "");
            } else {
                keyHex = bytesToHexString(parseByteArray(keyText));
            }
            sb.append("密钥: ").append(formatHexString(keyHex)).append("\n");
            sb.append("密钥长度: ").append(keyHex.length() / 2).append(" 字节\n");
            
            // 显示密钥类型和分解
            boolean isDoubleLength = (keyHex.length() == 32);
            sb.append("密钥类型: ").append(isDoubleLength ? "双长度" : "三长度").append("\n");
            
            // 显示 K1, K2, K3 分解
            if (isDoubleLength) {
                String k1 = keyHex.substring(0, 16);
                String k2 = keyHex.substring(16, 32);
                sb.append("K1 = ").append(formatHexString(k1)).append(" (CBC加密)\n");
                sb.append("K2 = ").append(formatHexString(k2)).append(" (最后解密)\n");
                sb.append("K3 = K1 (最后加密)\n");
            } else {
                String k1 = keyHex.substring(0, 16);
                String k2 = keyHex.substring(16, 32);
                String k3 = keyHex.substring(32, 48);
                sb.append("K1 = ").append(formatHexString(k1)).append(" (CBC加密)\n");
                sb.append("K2 = ").append(formatHexString(k2)).append(" (最后解密)\n");
                sb.append("K3 = ").append(formatHexString(k3)).append(" (最后加密)\n");
            }
        } catch (Exception e) {
            sb.append("密钥: 无法解析\n");
        }
        sb.append("\n");
        
        // IV 信息
        if (!ivText.isEmpty()) {
            sb.append("【IV 信息】\n");
            sb.append("输入模式: ").append(isIvHex ? "十六进制" : "字节数组").append("\n");
            try {
                String ivHex;
                if (isIvHex) {
                    ivHex = ivText.replaceAll("\\s+", "");
                } else {
                    ivHex = bytesToHexString(parseByteArray(ivText));
                }
                sb.append("IV: ").append(formatHexString(ivHex)).append("\n");
            } catch (Exception e) {
                sb.append("IV: 无法解析\n");
            }
            sb.append("\n");
        }
        

        sb.append("【算法参数】\n");
        sb.append("算法: ISO9797 Algorithm 3\n");
        sb.append("别名: ANSI X9.19 Retail MAC\n");
        sb.append("填充模式: ").append(paddingMode).append("\n");
        sb.append("加密引擎: DES\n");
        sb.append("工作模式: CBC\n\n");
        
        sb.append("【MAC 结果】\n");
        sb.append("十六进制:\n").append(formatHexString(macValue)).append("\n\n");
        sb.append("字节数组:\n").append(formatHexAsBytes(macValue)).append("\n\n");
        sb.append("长度: ").append(macValue.length() / 2).append(" 字节 (")
          .append(macValue.length() * 4).append(" 位)\n");
        
        tvResult.setText(sb.toString());
        scrollToTop();
    }
    
    /**
     * 显示错误信息
     */
    private void showError(String message) {
        StringBuilder sb = new StringBuilder();
        sb.append("========== 错误 ==========\n\n");
        sb.append(message);
        tvResult.setText(sb.toString());
        scrollToTop();
    }
    
    /**
     * 格式化十六进制字符串（每4个字符一组）
     */
    private String formatHexString(String hex) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < hex.length(); i += 4) {
            if (i > 0 && i % 32 == 0) {
                sb.append("\n");
            } else if (i > 0) {
                sb.append(" ");
            }
            int end = Math.min(i + 4, hex.length());
            sb.append(hex.substring(i, end));
        }
        return sb.toString();
    }
    
    /**
     * 格式化为字节数组格式
     */
    private String formatHexAsBytes(String hex) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (int i = 0; i < hex.length(); i += 2) {
            if (i > 0) sb.append(", ");
               if (i > 0 && i % 16 == 0) sb.append("\n ");
            // 将十六进制转换为十进制
            String hexPair = hex.substring(i, i + 2);
            int byteValue = Integer.parseInt(hexPair, 16);
            // 处理负数情况（Java中byte是有符号的）
            if (byteValue > 127) {
                byteValue -= 256;
            }
            sb.append(byteValue);
        }
        sb.append("]");
        return sb.toString();
    }
    
    /**
     * 字节数组转十六进制字符串
     */
    private String bytesToHexString(byte[] bytes) {
        StringBuilder sb = new StringBuilder();
        for (byte b : bytes) {
            sb.append(String.format("%02X", b & 0xFF));
        }
        return sb.toString();
    }

    public void updateByteBlock(int dataSize) {
        try {
            if (dataSize >= 16 && dataSize < 64) {
                Thread.sleep(1);
            } else if (dataSize >= 64 && dataSize < 256) {
                Thread.sleep(1);
            } else if (dataSize >= 256 && dataSize < 1024) {
                Thread.sleep(2);
            } else if (dataSize >= 1024 && dataSize < 4096) {
                Thread.sleep(2);
            } else if (dataSize >= 4096) {
                Thread.sleep(5);
            }
        } catch (InterruptedException e) {
            // 忽略中断异常
            Thread.currentThread().interrupt();
        }
    }
    
    /**
     * 滚动到顶部
     */
    private void scrollToTop() {
        scrollView.post(new Runnable() {
            @Override
            public void run() {
                scrollView.fullScroll(View.FOCUS_UP);
            }
        });
    }
    
    // ========== 辅助方法 ==========
    
    
    /**
     * 解析字节数组格式的字符串
     * 支持格式: [1, 2, 3] 或 [-124, -28, 0, -128]
     */
    private byte[] parseByteArray(String input) {
        // 移除空格和方括号
        input = input.trim();
        if (input.startsWith("[")) {
            input = input.substring(1);
        }
        if (input.endsWith("]")) {
            input = input.substring(0, input.length() - 1);
        }
        
        // 分割并解析
        String[] parts = input.split(",");
        byte[] result = new byte[parts.length];
        
        for (int i = 0; i < parts.length; i++) {
            String part = parts[i].trim();
            try {
                int value = Integer.parseInt(part);
                if (value < -128 || value > 127) {
                    throw new IllegalArgumentException(
                        "字节值超出范围: " + value + " (必须在 -128 到 127 之间)"
                    );
                }
                result[i] = (byte) value;
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException(
                    "无法解析字节值: " + part
                );
            }
        }
        
        return result;
    }
    
    /**
     * 创建指定字节大小的十六进制数据
     * @param byteSize 字节大小 (16, 64, 256, 1024, 4096)
     * @returns 十六进制字符串
     */
    private String createHexData(int byteSize) {
        // 创建指定大小的字节数组
        byte[] data = new byte[byteSize];

        // 填充数据，这里使用简单的模式填充
        for (int i = 0; i < byteSize; i++) {
            // 使用模运算创建一些变化的数据
            data[i] = (byte) (i % 256);
        }

        // 转换为十六进制字符串
        return bytesToHexString(data);
    }


    /**
     * 运行十六进制示例的性能测试
     */
    private void runHexExamplePerformanceTest(int num) {
        try {
            String keyHex = "319CD05D11BB06729BE23DA19B80E6A3";
            String ivHex = "A097994108D06F1B";
            

            Log.i("ISO9797Alg3Mac", "开始性能测试");
            
            Log.i("ISO9797Alg3Mac", "testlog:: ISO9797Alg3Mac " + num + "字节 start ");

            // 为当前数据大小创建测试数据
            String hexInput = createHexData(num);
            byte[] inputBytes = macHelper.hexStringToBytes(hexInput);

            try {
                calculateMACWithDetailedTiming(inputBytes, keyHex, ivHex);
            } catch (Exception e) {
                Log.e("ISO9797Alg3Mac", "测试失败 , 错误: " + e.getMessage());
            }

            Log.i("ISO9797Alg3Mac", "testlog:: ISO9797Alg3Mac " + num +" 字节  end ");

            Log.i("ISO9797Alg3Mac", "所有性能测试完成");
        } catch (Exception e) {
            Log.e("ISO9797Alg3Mac", "运行性能测试时出错: " + e.getMessage());
            e.printStackTrace();
        }
    }
}